package cn.itqiqi.student_system_java.controller;

import cn.itqiqi.student_system_java.pojo.Teacher;
import cn.itqiqi.student_system_java.service.impl.TeacherServiceImpl;
import cn.itqiqi.student_system_java.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kevin_琪琪
 * @version 1.0
 * @description
 * @date 2022-06-21 10:44
 */
@RestController
public class TeacherController {

    @Autowired
    private TeacherServiceImpl teacherService;
    @Autowired
    private ResultUtils resultUtils;

    @GetMapping("/getTeacherAll")
    public String getTeacherAll(Long pageNum, Long pageSize) {
        return teacherService.getTeacherAll(pageNum, pageSize);
    }
    @GetMapping("/getTeacherSelect")
    public String getTeacherSelect(Long pageNum, Long pageSize, String selectValue, String queryValue) {
        if (selectValue.equals("tname")) {
            return teacherService.getTeacherByName(pageNum, pageSize, queryValue);
        } else if (selectValue.equals("classGuide")) {
            return teacherService.getTeacherByClassGuide(pageNum, pageSize, queryValue);
        } else {
            return resultUtils.fail(400, "参数不合法！");
        }
    }

    @PostMapping("/addTeacher")
    public String addTeacher(@RequestBody Teacher teacher) {
        return teacherService.addTeacher(teacher);
    }

    @PostMapping("/deleteTeacher")
    public String deleteTeacher(@RequestBody Teacher teacher) {
        return teacherService.deleteTeacher(Integer.parseInt(teacher.getTid().toString()));
    }

    @PostMapping("/updateTeacher")
    public String updateTeacher(@RequestBody Teacher teacher) {
        return teacherService.updateTeacher(teacher);
    }

}
